<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MilestoneMain
 *
 * @author agama
 */
class MilestoneMain extends Milestone
{

    protected $previosLinks = array( );
    protected $section_policy;
    protected $section_id;
    protected $section_index = 0;
    protected $users_list = false;

    function __construct()
    {
        parent::__construct( 'incidents', 50, 'milestone=' . $this->id,
                array( 'when' => 1 ) );
    }

    function setSection( $policy, $id )
    {
        $this->section_policy = $policy;
        $this->section_id = $id;
    }

    function handleGET( Event $e )
    {

        if ( $e->tag == 'change_section' && in_array( $_GET[ 'section' ],
                        array( 'events_list', 'files_list', 'project_users_list',
                    'time_line' ) ) ) {
            $this->setSection( $_GET[ 'section' ], $_GET[ 'section' ] );
            $e->cancelBubble();
        }
    }

    function fill()
    {
        //A partir de la traza tengo que crear los enlaces hacia atrás, empezando por el projecto


        $previous = MyLink::$default->get_rows( 'SELECT id, description FROM milestones WHERE id IN (' . $this->trace . ')',
                        true )->toArray();
        $parts = explode( ',', $this->trace );
        foreach ( $parts as $p ) {
            foreach ( $previos as $prev ) {
                if ( $prev[ 0 ] == $p ) {
                    $this->previousLinks[ $p ] = $prev[ 1 ];
                    break;
                }
            }
        }

        //tengo qeu cargar la lista de milestones hijos
        $childMilestones = array( );
        Node::getArray( 'milestone', $childMilestones, 'milestone=' . $this->id,
                array( 'descripcion' => 1 ) );
        foreach ( $childMilestones as $c ) $this->appendChild( $c );

        //obtenemos las incidencias o los archivos de toda la traza
        $this->appendChild( Node::getInstance( $this->section_policy,
                        $this->trace ) );
    }

}

?>
